package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyCode;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.base.bean.JyCustomerProvider;
import com.jy.adscm.operation.base.mapper.mysql.JyCustomerProviderMapper;
import com.jy.adscm.operation.mscyb.bean.JqwbMachinemaintenance;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqwbMachinemaintenanceMapper;
import com.jy.adscm.operation.mscyb.service.JqwbMachinemaintenanceService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyCodeMapper;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-12-07
 */
@Service
public class JqwbMachinemaintenanceServiceImpl extends ServiceImpl<JqwbMachinemaintenanceMapper, JqwbMachinemaintenance> implements JqwbMachinemaintenanceService {
   @Autowired
    JyCustomerProviderMapper jyCustomerProviderMapper;
   @Autowired
    JyUserMapper jyUserMapper;
   @Autowired
    JyCodeMapper jyCodeMapper;
    @Override
    public List<JqwbMachinemaintenance> selectjqwbMachinemaintenances() {
        List<JqwbMachinemaintenance> jqwbMachinemaintenances = super.selectList(null);
        for (JqwbMachinemaintenance jqwbMachinemaintenance : jqwbMachinemaintenances) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqwbMachinemaintenance.getCreateperson(),null)){
                JyUser jyUser = jyUserMapper.selectById(jqwbMachinemaintenance.getCreateperson());
                if (jyUser==null){
                    jqwbMachinemaintenance.setCreatepersonName(jqwbMachinemaintenance.getCreateperson());
                }else {
                    jqwbMachinemaintenance.setCreatepersonName(jyUser.getName());
                }

            }
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqwbMachinemaintenance.getUserdeptname(),null)){
                JyCustomerProvider jyCustomerProvider = jyCustomerProviderMapper.selectById(jqwbMachinemaintenance.getUserdeptname());
                if(jyCustomerProvider==null){
                    jqwbMachinemaintenance.setUserdeptnameName(jqwbMachinemaintenance.getUserdeptname());
                }else {
                    jqwbMachinemaintenance.setUserdeptnameName(jyCustomerProvider.getName());
                }
            }
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqwbMachinemaintenance.getMachinename(),null)){
                JyCode jyCode = jyCodeMapper.selectById(jqwbMachinemaintenance.getMachinename());
                if(jyCode==null){
                    jqwbMachinemaintenance.setMachinenameName(jqwbMachinemaintenance.getMachinename());
                }else {
                    jqwbMachinemaintenance.setMachinenameName(jyCode.getName());
                }
            }
        }
        return jqwbMachinemaintenances;
    }

    @Override
    public List<JyCustomerProvider> queryCustomer() {
        Wrapper<JyCustomerProvider> wrapper =new EntityWrapper<>();
        wrapper.eq("TYPE",1);
        wrapper.setSqlSelect("ID","NAME");
        List<JyCustomerProvider> jyCustomerProviders = jyCustomerProviderMapper.selectList(wrapper);
        return jyCustomerProviders;
    }
}
